﻿using System.Threading.Tasks;
using Keede.RabbitMQ;
using log4net;
using RabbitMQ.Client.Events;

namespace Keede.Rabbitmq.HandleService
{
    public abstract class BaseMsgListener<T>
    {
        protected ILog _logger;

        public IQueueListener Listener { get; }

        /// <summary>
        /// 监听对应的服务名称（即在配置中心配置的服务名）
        /// </summary>
        public string ServerName { get; protected set; }

        protected BaseMsgListener()
        {
            this._logger = LogManager.GetLogger(typeof(BaseMsgListener<>));
            this.Listener = new QueueListener()
            {
                QueueName = typeof(T).Name,
                MessageReceivedHandler = async (s, args) => await this.MessageReceivedHandler(s, args)
            };
        }

        public abstract Task<bool> MessageReceivedHandler(string message, BasicDeliverEventArgs args);
    }
}
